package com.summer.media.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.summer.media.pojo.MediaProcess;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Mr.chen
 * @since 2023-03-28
 */
public interface MediaProcessMapper extends BaseMapper<MediaProcess> {
    @Select("select * from media_process\n" +
            "         where id % #{total} = #{index} and status in (1,3) and fail_count <= 3\n" +
            "        limit #{taskNum};")
    List<MediaProcess> getTask(@Param("total") int total, @Param("index") int index, @Param("taskNum") int taskNum);

    @Update("update media_process\n" +
            "set status = 4\n" +
            "where id = #{id} and status in (1,3) and fail_count <= 3;")
    int getLock(@Param("id") Long id);
}
